package io.github.jsp.util;

import java.util.concurrent.ThreadLocalRandom;

/**
 * ID生成器工具类
 */

public class IdGeneratorUtil {
    
    private static final SnowflakeIdGenerator snowflakeGenerator = SnowflakeIdGenerator.getInstance();
    
    /**
     * 生成雪花算法ID
     */
    public static long generateSnowflakeId() {
        return snowflakeGenerator.nextId();
    }
    
    /**
     * 生成字符串格式的雪花算法ID
     */
    public static String generateSnowflakeIdString() {
        return String.valueOf(snowflakeGenerator.nextId());
    }
    
    /**
     * 解析雪花算法ID
     */
    public static SnowflakeIdGenerator.SnowflakeIdInfo parseSnowflakeId(long id) {
        return snowflakeGenerator.parseId(id);
    }
    
    /**
     * 批量生成ID
     */
    public static long[] generateBatchIds(int count) {
        if (count <= 0) {
            throw new IllegalArgumentException("Count must be positive");
        }
        
        long[] ids = new long[count];
        for (int i = 0; i < count; i++) {
            ids[i] = snowflakeGenerator.nextId();
        }
        return ids;
    }
    
    /**
     * 获取生成器信息
     */
    public static String getGeneratorInfo() {
        return snowflakeGenerator.getInfo();
    }
    
    /**
     * 生成随机ID（用于测试或备用）
     */
    public static long generateRandomId() {
        return ThreadLocalRandom.current().nextLong(1000000000000000L, 9999999999999999L);
    }
}